#[cfg(test)]
mod test {
    use super::parser::*;
    use super::tools::*;

    #[test]
    fn predicate_combinator() {
        let parser = pred(any_char, |c| *c == 'o');
        assert_eq!(Ok(("mg", 'o')), parser.parse("omg"));
        assert_eq!(Err("lol"), parser.parse("lol"));
    }

    #[test]
    fn pipe_combinator() {
        let get_tag = right(match_literal("<"), identifier);
        assert_eq!(
            Ok(("/>", "my-first-element")),
            get_tag.parse("<my-first-element/>")
        );
    }

    #[test]
    fn one_or_more_combinator() {
        let parser = one_or_more(match_literal("ha"));
        assert_eq!(Ok(("hel", vec![(), (), ()])), parser.parse("hahahahel"));
        assert_eq!(Err("ahah"), parser.parse("ahah"));
        assert_eq!(Err(""), parser.parse(""));
    }

    #[test]
    fn pair_combinator() {
        let tag_opener = pair(match_literal("<"), identifier);
        assert_eq!(
            Ok(("/>", ((), "my-first-element"))),
            tag_opener("<my-first-element/>")
        );
        assert_eq!(Err("oops"), tag_opener("oops"));
        assert_eq!(Err("!oops"), tag_opener("<!oops"));
    }

    #[test]
    fn test_match_literal() {
        let match_abc = match_literal("abc");
        assert_eq!(match_abc.parse("abc_我"), Ok(("_我", ())));
        assert_eq!(match_abc.parse("hello"), Err("hello"));
    }

    #[test]
    fn test_indentifier() {
        assert_eq!(identifier("hello"), Ok(("", "hello")));
        assert_eq!(identifier("hello fuck"), Ok((" fuck", "hello")));
        assert_eq!(identifier(" hello fuck"), Err(" hello fuck"));
        assert_eq!(identifier(""), Err(""));

        assert_eq!(
            Ok(("", "i-am-an-identifier")),
            identifier("i-am-an-identifier")
        );
        assert_eq!(
            Ok((" entirely an identifier", "not")),
            identifier("not entirely an identifier")
        );
        assert_eq!(
            Err("!not at all an identifier"),
            identifier("!not at all an identifier")
        );
    }
}

mod parser;
mod tools;
mod xml;
